package com.bit.principle.component;

import com.bit.principle.model.Dog;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

//@Component
public class BeanLifeComponent implements BeanNameAware {
    private Dog singletonDog;


    public BeanLifeComponent() {
        System.out.println("执行构造方法");
    }

    @Autowired
    public void setSingletonDog(Dog singletonDog) {
        this.singletonDog = singletonDog;
        System.out.println("属性注入完成");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("执行BeanNameAware, name:"+ name);
    }

    @PostConstruct
    public void init(){
        System.out.println("执行初始化方法");
    }

    public void use(){
        System.out.println("执行use 方法");
    }

    @PreDestroy
    public void destroy(){
        System.out.println("执行destroy方法");
    }

}
